package com.cskaoyan.mall.product.controller;

import com.cskaoyan.mall.common.result.Result;
import com.cskaoyan.mall.product.dto.FirstLevelCategoryDTO;
import com.cskaoyan.mall.product.dto.SecondLevelCategoryDTO;
import com.cskaoyan.mall.product.dto.ThirdLevelCategoryDTO;
import com.cskaoyan.mall.product.dto.TrademarkDTO;
import com.cskaoyan.mall.product.query.CategoryTrademarkParam;
import com.cskaoyan.mall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Pudding
 * @Date 2024/6/29 15:04
 */
@RestController
public class AdminCategoryController {

    @Autowired
    CategoryService categoryService;

    //1. 查询一级分类
    // GET http://localhost/admin/product/getCategory1
    @GetMapping("/admin/product/getCategory1")
    public Result<List<FirstLevelCategoryDTO>> getCategory1(){

        List<FirstLevelCategoryDTO> firstLevelCategoryDTOS = categoryService.getFirstLevelCategory();
        return Result.ok(firstLevelCategoryDTOS);
    }

    //2. 根据一级分类查询二级分类
    @GetMapping("/admin/product/getCategory2/{firstLevelCategoryId}")
    public Result<List<SecondLevelCategoryDTO>> getCategory2(@PathVariable Long firstLevelCategoryId){

        List<SecondLevelCategoryDTO> secondLevelCategoryDTOS = categoryService.getSecondLevelCategory(firstLevelCategoryId);

        return Result.ok(secondLevelCategoryDTOS);
    }

    //3. 根据二级分类，查询三级分类
    @GetMapping("/admin/product/getCategory3/{category2Id}")
    public Result<List<ThirdLevelCategoryDTO>> getCategory3(@PathVariable Long category2Id){

        List<ThirdLevelCategoryDTO> thirdLevelCategoryDTOS = categoryService.getThirdLevelCategory(category2Id);
        return Result.ok(thirdLevelCategoryDTOS);
    }

    //4. 添加商品类目品牌
    @PostMapping("admin/product/baseCategoryTrademark/save")
    public Result save(@RequestBody CategoryTrademarkParam categoryTrademarkVo){

        categoryService.save(categoryTrademarkVo);
        return Result.ok();
    }

    //5. 查询商品类目品牌
    @GetMapping("admin/product/baseCategoryTrademark/findTrademarkList/{thirdLevelCategoryId}")
    public Result findTrademarkList(@PathVariable Long thirdLevelCategoryId){

        List<TrademarkDTO> trademarkDTOList = categoryService.findTrademarkList(thirdLevelCategoryId);
        return Result.ok(trademarkDTOList);
    }

    //6. 查询未关联商品类目的品牌
    @GetMapping("admin/product/baseCategoryTrademark/findCurrentTrademarkList/{thirdLevelCategoryId}")
    public Result findCurrentTrademarkList(@PathVariable Long thirdLevelCategoryId){

        List<TrademarkDTO> unLinkedTrademarkList = categoryService.findUnLinkedTrademarkList(thirdLevelCategoryId);
        return Result.ok(unLinkedTrademarkList);
    }

    //7. 删除目录品牌关联
    @DeleteMapping("admin/product/baseCategoryTrademark/remove/{thirdLevelCategoryId}/{trademarkId}")
    public Result remove(@PathVariable Long thirdLevelCategoryId, @PathVariable Long trademarkId){

        categoryService.remove(thirdLevelCategoryId, trademarkId);
        return Result.ok();
    }
}
